var lsb = {
    groupCnt: -1,
    routateTable: [],
    findDSwitch: function(e) {
        for (var t = [], n = Model.elements, i = 0; i < n.length; i++) if ("SWITCH" == n[i].category) {
            t = Model.findOther(i, e);
            for (var a = 0; a < t.length; a++) {
                var o = Model.getNodeByID(Model.getIndexByID(t[a]));
                if ( - 1 == o.otherSwitch && Utils.inPoint(e, n[i].component.chaWan[1], o.component.chaWan[1])) {
                    var s = Utils.calcuAngel(n[i].component.chaWan[0], n[i].component.chaWan[1]),
                        r = Utils.calcuAngel(o.component.chaWan[0], o.component.chaWan[1]);
                    180 * Math.abs(s - r) / Math.PI < 20 && (n[i].otherSwitch = o.id, n[i].wanNode = o.id, o.otherSwitch = n[i].id, o.wanNode = n[i].id)
                }
            }
        }
        for (var i = 0; i < n.length; i++) if ("SWITCH" == n[i].category && -1 == n[i].otherSwitch) {
            t = Model.findOther(i, e);
            for (var a = 0; a < t.length; a++) {
                var o = Model.getNodeByID(Model.getIndexByID(t[a]));
                if ( - 1 == o.otherSwitch && Utils.inPoint(e, n[i].component.chaZhi[1], o.component.chaZhi[1])) {
                    var s = Utils.calcuAngel(n[i].component.chaWan[0], n[i].component.chaWan[1]),
                        r = Utils.calcuAngel(o.component.chaWan[0], o.component.chaWan[1]);
                    180 * Math.abs(s - r) / Math.PI < 25 && (n[i].otherSwitch = o.id, n[i].zhiNode = o.id, o.otherSwitch = n[i].id, o.zhiNode = n[i].id)
                }
            }
        }
        for (var i = 0; i < n.length; i++) if ("SWITCH" == n[i].category && -1 != n[i].otherSwitch && -1 == n[i].otherDoubleCrossover) for (var a = i + 1; a < n.length; a++) if ( - 1 == n[a].otherDoubleCrossover && -1 != n[a].otherSwitch && n[i].otherSwitch != n[a].id && Utils.inPoint(e, n[i].component.chaWan[1], n[a].component.chaWan[1])) {
            n[i].otherDoubleCrossover = n[a].id;
            var o = Model.getIndexByID(n[i].otherSwitch);
            n[o].otherDoubleCrossover = n[a].id,
                n[a].otherDoubleCrossover = n[i].id,
                o = Model.getIndexByID(n[a].otherSwitch),
                n[o].otherDoubleCrossover = n[i].id
        }
    },
    findSignalRelation: function(e) {
        for (var t = Model.elements,
                 n = 0; n < t.length; n++) if ("DIAO" == t[n].type.match("DIAO") && -1 == t[n].otherSignal) {
            var i, a, o = !1,
                s = t[n].component.base[0],
                r = t[n].component.firstLight[0];
            s.x < r.x ? (i = t[n].component.base[1], a = 4.1 * t[n].RADIUS) : (i = t[n].component.base[1], a = 4.1 * -t[n].RADIUS);
            for (var l = n + 1; l < t.length; l++) if ("DIAO" == t[l].type.match("DIAO")) {
                if (o) break;
                if (s = t[l].component.base[0], r = t[l].component.firstLight[0], a > 0) {
                    if (s.x < r.x) continue
                } else if (s.x > r.x) continue;
                var f = t[l].component.base[1],
                    h = e.getContext("2d");
                if (h.beginPath(), h.rect(i.x - 5 * t[n].lineWidth, i.y, 10 * t[n].lineWidth, a), h.isPointInPath(f.x, f.y)) for (var p = 0; p < t.length && !o; p++) {
                    var c = [];
                    "SWITCH" == t[p].category ? (c.push(t[p].component.chaJian[0]), c.push(t[p].component.chaWan[1]), c.push(t[p].component.chaZhi[1])) : "TRACK" == t[p].category && (c.push(t[p].component.point[0]), c.push(t[p].component.point[1]));
                    for (var d = 0; d < c.length; d++) if (h.isPointInPath(c[d].x, c[d].y)) {
                        t[n].otherSignal = t[l].id,
                            t[l].otherSignal = t[n].id,
                            t[n].bingZhi = !0,
                            t[l].bingZhi = !0,
                            o = !0;
                        break
                    }
                }
            }
        }
        for (n = 0; n < t.length; n++) if ("TRACK" == t[n].category && "WCQD" == t[n].trackType) {
            s = t[n].component.point[0],
                r = t[n].component.point[1];
            var h = e.getContext("2d");
            h.beginPath(),
                h.rect(s.x - 1.5 * t[n].lineWidth, s.y - 5 * t[n].lineWidth, 3 * t[n].lineWidth, 10 * t[n].lineWidth);
            var c = [];
            for (l = 0; l < t.length; l++)"SIGNAL" == t[l].category && (h.isPointInPath(t[l].component.base[0].x, t[l].component.base[0].y) || h.isPointInPath(t[l].component.base[1].x, t[l].component.base[1].y)) && c.push(l);
            h.beginPath(),
                h.rect(r.x - 1.5 * t[n].lineWidth, r.y - 5 * t[n].lineWidth, 3 * t[n].lineWidth, 10 * t[n].lineWidth),
                h.stroke();
            var g = [];
            for (l = 0; l < t.length; l++) if ("SIGNAL" == t[l].category) {
                if ("LIE" == t[l].type.match("LIE")) continue; (h.isPointInPath(t[l].component.base[0].x, t[l].component.base[0].y) || h.isPointInPath(t[l].component.base[1].x, t[l].component.base[1].y)) && g.push(l)
            }
            if (c.length > 0 && g.length > 0) {
                if (t[c[0]].aspect == t[g[0]].aspect) continue;
                t[c[0]].otherSignal = t[g[0]].id,
                    t[g[0]].otherSignal = t[c[0]].id,
                    t[c[0]].chaZhi = !0,
                    t[g[0]].chaZhi = !0
            }
        }
    },
    findNetStruct: function(e) {
        function t(e) {
            for (var t = Model.elements,
                     i = 0; i < t.length; i++) if ("SWITCH" == t[i].category && -1 == t[i].qianNode) {
                var a = n(t, i, t[i].component.chaJian[0]),
                    o = a.index;
                if (t[i].qianNode = Model.getIDByIndex(o), -1 == t[i].zhiNode) {
                    var a = n(t, i, t[i].component.chaZhi[1]),
                        o = a.index;
                    if (t[i].zhiNode = Model.getIDByIndex(o), -1 == t[i].wanNode) {
                        var a = n(t, i, t[i].component.chaWan[1]),
                            o = a.index;
                        t[i].wanNode = Model.getIDByIndex(o)
                    }
                }
            }
        }
        function n(t, n, i) {
            for (var a = {
                    index: -1,
                    p: ""
                },
                     o = 0; o < t.length; o++) if (o != n) if ("SWITCH" == t[o].category) {
                if (Utils.inPoint(e, i, t[o].component.chaJian[0])) return a.index = o,
                    a.p = t[o].component.chaJian[1],
                    a;
                if (Utils.inPoint(e, i, t[o].component.chaZhi[1])) return a.index = o,
                    a.p = t[o].component.chaJian[1],
                    a;
                if (Utils.inPoint(e, i, t[o].component.chaWan[1])) return a.index = o,
                    a.p = t[o].component.chaJian[1],
                    a
            } else if ("TRACK" == t[o].category) {
                if (Utils.inPoint(e, i, t[o].component.point[0])) return a.index = o,
                    a.p = t[o].component.point[1],
                    a;
                if (Utils.inPoint(e, i, t[o].component.point[1])) return a.index = o,
                    a.p = t[o].component.point[0],
                    a
            }
            return a
        }
        function i(e) {
            for (var t = Model.elements,
                     i = 0; i < t.length; i++) if ("TRACK" == t[i].category) {
                var a = n(t, i, t[i].component.point[0]),
                    o = a.index; - 1 != o && (t[i].component.point[0].x < a.p.x ? t[i].houNode = Model.getIDByIndex(o) : t[i].qianNode = Model.getIDByIndex(o));
                var a = n(t, i, t[i].component.point[1]),
                    o = a.index; - 1 != o && (t[i].component.point[1].x < a.p.x ? t[i].houNode = Model.getIDByIndex(o) : t[i].qianNode = Model.getIDByIndex(o))
            }
        }
        function a(e) {
            for (var t = Model.elements,
                     n = 0; n < t.length; n++) if ("SIGNAL" == t[n].category) {
                t[n].bingZhi && (t[n].component.base[0].x < t[n].component.firstLight[0].x ? (t[n].qianNode = t[Model.getIndexByID(t[n].otherSignal)].id, t[Model.getIndexByID(t[n].otherSignal)].houNode = t[n].id) : (t[n].houNode = t[Model.getIndexByID(t[n].otherSignal)].id, t[Model.getIndexByID(t[n].otherSignal)].qianNode = t[n].id));
                var i, a, o = t[n].component.base[0],
                    s = t[n].component.firstLight[0];
                o.x < s.x ? (i = t[n].component.base[1], a = 2.1 * t[n].RADIUS) : (i = t[n].component.base[1], a = 2.1 * -t[n].RADIUS);
                var r = e.getContext("2d");
                r.beginPath(),
                    r.rect(i.x - 5 * t[n].lineWidth, i.y, 10 * t[n].lineWidth, a),
                    r.stroke();
                for (var l = [], f = 0; f < t.length; f++) if ("SIGNAL" != t[f].category) {
                    var h = {
                        index: -1,
                        cp: "",
                        point: -1
                    };
                    "SWITCH" == t[f].category ? (r.isPointInPath(t[f].component.chaJian[0].x, t[f].component.chaJian[0].y) && (h.index = f, h.cp = "QIAN", h.point = t[f].component.chaJian[1], l.push(h)), r.isPointInPath(t[f].component.chaZhi[1].x, t[f].component.chaZhi[1].y) && (h.index = f, h.cp = "ZHI", h.point = t[f].component.chaJian[1], l.push(h)), r.isPointInPath(t[f].component.chaWan[1].x, t[f].component.chaWan[1].y) && (h.index = f, h.cp = "WAN", h.point = t[f].component.chaJian[1], l.push(h))) : "TRACK" == t[f].category && (r.isPointInPath(t[f].component.point[0].x, t[f].component.point[0].y) ? (h.index = f, h.cp = "0", h.point = t[f].component.point[1], l.push(h)) : r.isPointInPath(t[f].component.point[1].x, t[f].component.point[1].y) && (h.index = f, h.cp = "1", h.point = t[f].component.point[0], l.push(h)))
                }
                for (var p = 0; p < l.length; p++) o.x < l[p].point.x ? t[n].bingZhi ? -1 == t[n].houNode && (t[n].houNode = Model.getIDByIndex(l[p].index), "QIAN" == l[p].cp ? t[l[p].index].qianNode = t[n].id: "ZHI" == l[p].cp ? t[l[p].index].zhiNode = t[n].id: "WAN" == l[p].cp ? t[l[p].index].wanNode = t[n].id: t[l[p].index].qianNode = t[n].id) : (t[n].houNode = Model.getIDByIndex(l[p].index), "QIAN" == l[p].cp ? t[l[p].index].qianNode = t[n].id: "ZHI" == l[p].cp ? t[l[p].index].zhiNode = t[n].id: "WAN" == l[p].cp ? t[l[p].index].wanNode = t[n].id: t[l[p].index].qianNode = t[n].id) : t[n].bingZhi ? -1 == t[n].qianNode && (t[n].qianNode = Model.getIDByIndex(l[p].index), "QIAN" == l[p].cp ? t[l[p].index].qianNode = t[n].id: "ZHI" == l[p].cp ? t[l[p].index].zhiNode = t[n].id: "WAN" == l[p].cp ? t[l[p].index].wanNode = t[n].id: t[l[p].index].houNode = t[n].id) : (t[n].qianNode = Model.getIDByIndex(l[p].index), "QIAN" == l[p].cp ? t[l[p].index].qianNode = t[n].id: "ZHI" == l[p].cp ? t[l[p].index].zhiNode = t[n].id: "WAN" == l[p].cp ? t[l[p].index].wanNode = t[n].id: t[l[p].index].houNode = t[n].id)
            }
        }
        function o(e) {
            for (var t = Model.elements,
                     n = 0; n < t.length; n++) if ("BUTTON" == t[n].category && "BGBUTTON" == t[n].buttonType) {
                var i = Utils.copy(t[n].component.point[0]);
                i.x -= t[n].length / 8,
                    i.y += t[n].length;
                var a = e.getContext("2d");
                a.beginPath(),
                    a.rect(i.x, i.y, 1.2 * t[n].length, 1.2 * t[n].length),
                    a.stroke();
                for (var o = 0; o < t.length; o++)"SWITCH" == t[o].category && (a.isPointInPath(t[o].component.chaJian[0].x, t[o].component.chaJian[0].y) ? (t[o].extraButton.id = t[n].id, t[o].extraButton.type = t[n].buttonType, t[o].extraButton.pos = "CJ", t[o].extraButton.name = t[n].name) : a.isPointInPath(t[o].component.chaZhi[1].x, t[o].component.chaZhi[1].y) ? (t[o].extraButton.id = t[n].id, t[o].extraButton.type = t[n].buttonType, t[o].extraButton.pos = "CZ", t[o].extraButton.name = t[n].name) : a.isPointInPath(t[o].component.chaWan[1].x, t[o].component.chaWan[1].y) ? (t[o].extraButton.id = t[n].id, t[o].extraButton.type = t[n].buttonType, t[o].extraButton.pos = "CW", t[o].extraButton.name = t[n].name) : (a.isPointInPath(t[o].component.chaZhi[0].x, t[o].component.chaZhi[0].y) || a.isPointInPath(t[o].component.chaWan[0].x, t[o].component.chaWan[0].y) || a.isPointInPath(t[o].component.chaJian[1].x, t[o].component.chaJian[1].y)) && (t[o].extraButton.id = t[n].id, t[o].extraButton.type = t[n].buttonType, t[o].extraButton.pos = "CX", t[o].extraButton.name = t[n].name))
            }
        }
        t(e),
            i(e),
            a(e),
            o(e)
    },
    switchPart: function(e, t, n) {
        return Utils.inPoint(n, Model.elements[t].component.chaJian[0], e) ? "QIAN": Utils.inPoint(n, Model.elements[t].component.chaWan[1], e) ? "WAN": Utils.inPoint(n, Model.elements[t].component.chaZhi[1], e) ? "ZHI": void 0
    },
    findRoute: function() {
        function e() {
            for (var e = Model.elements,
                     t = [], n = {
                    index: -1,
                    aspect: "",
                    type: "",
                    flag: "",
                    part: {
                        cp: "",
                        rp: ""
                    },
                    bg: !1
                },
                     i = 0; i < e.length; i++) if ("SIGNAL" == e[i].category) {
                if ("DIAO" == e[i].type.match("DIAO")) {
                    for (var s = !1,
                             r = 0; r < e[i].button.length; r++) if ("DLBUTTON" == e[i].button[r]) {
                        s = !0;
                        break
                    }
                    if (!s) continue
                }
                n.index = i,
                    n.type = "SIGNAL",
                    n.aspect = e[i].aspect,
                    t.push(n);
                for (var l = 0; t.length > 0;) {
                    var f = t[t.length - 1],
                        h = lsb.getNextNode(f.index, f.aspect, f.part);
                    if (h = Model.getIndexByID(h), -1 == h) a(t);
                    else if ("TRACK" == e[h].category) if ("GD" == e[h].trackType) a(t);
                    else {
                        var p = Utils.copy(n);
                        p.index = h,
                            p.type = "TRACK",
                            t.push(p)
                    } else if ("SWITCH" == e[h].category) {
                        if ("QIAN" == f.part.rp) {
                            var p = Utils.copy(n);
                            p.index = h,
                                p.type = "SWITCH",
                                p.flag = "QIAN",
                                p.part.cp = "ZHI",
                                p.part.rp = ""
                        } else if ("ZHI" == f.part.rp) {
                            var p = Utils.copy(n);
                            p.index = h,
                                p.type = "SWITCH",
                                p.flag = "ZHI",
                                p.part.cp = "QIAN",
                                p.part.rp = ""
                        } else if ("WAN" == f.part.rp) {
                            var p = Utils.copy(n);
                            p.index = h,
                                p.type = "SWITCH",
                                p.flag = "WAN",
                                p.part.cp = "QIAN",
                                p.part.rp = ""
                        }
                        t.push(p)
                    } else if ("SIGNAL" == e[h].category) if ("LIE" == e[h].type.match("LIE")) {
                        var p = Utils.copy(n);
                        if (p.index = h, p.type = "SIGNAL", t.push(p), f.aspect != e[h].aspect) {
                            if (("CZ" == e[h].signalType || "CZD" == e[h].signalType || "JL" === e[h].signalType || "TF" === e[h].signalType) && -1 != e[h].jg) {
                                var p = Utils.copy(n);
                                p.index = Model.getIndexByID(e[h].jg),
                                    p.type = "TRACK",
                                    t.push(p)
                            }
                            o(t, "LIE", l),
                                a(t),
                                l++
                        } else a(t)
                    } else if ("DIAO" == e[h].type.match("DIAO")) {
                        var c = !1,
                            p = Utils.copy(n);
                        p.index = h,
                            p.type = "SIGNAL",
                            t.push(p);
                        for (var d = 0; d < e[h].button.length; d++) if ("DLBUTTON" == e[h].button[d].match("DLBUTTON") || "LZBUTTON" == e[h].button[d].match("LZBUTTON")) {
                            if (c = !0, -1 != e[h].jg) {
                                var p = Utils.copy(n);
                                p.index = Model.getIndexByID(e[h].jg),
                                    p.type = "TRACK",
                                    t.push(p)
                            }
                            o(t, "LIE", l),
                                a(t),
                                l++;
                            break
                        }
                    }
                }
            }
        }
        function t() {
            for (var e = Model.elements,
                     t = [], s = {
                    index: -1,
                    aspect: "",
                    type: "",
                    flag: "",
                    part: {
                        cp: "",
                        rp: ""
                    },
                    bg: !1
                },
                     r = 0; r < e.length; r++) if ("SIGNAL" == e[r].category) {
                if ("LIE" == e[r].type.match("LIE")) {
                    for (var l = !1,
                             f = 0; f < e[r].button.length; f++) if ("DBUTTON" == e[r].button[f]) {
                        l = !0;
                        break
                    }
                    if (!l) continue
                }
                s.index = r,
                    s.type = "SIGNAL",
                    s.aspect = e[r].aspect,
                    t.push(s);
                for (var h = 0; t.length > 0;) {
                    var p = t[t.length - 1],
                        c = lsb.getNextNode(p.index, p.aspect, p.part);
                    if (c = Model.getIndexByID(c), -1 == c) a(t);
                    else if ("TRACK" == e[c].category) if ("GD" == e[c].trackType) a(t);
                    else {
                        var d = Utils.copy(s);
                        d.index = c,
                            d.type = "TRACK",
                            t.push(d)
                    } else if ("SWITCH" == e[c].category) {
                        if ("QIAN" == p.part.rp) {
                            var d = Utils.copy(s);
                            d.index = c,
                                d.type = "SWITCH",
                                d.flag = "QIAN",
                                d.part.cp = "ZHI",
                                d.part.rp = ""
                        } else if ("ZHI" == p.part.rp) {
                            var d = Utils.copy(s);
                            d.index = c,
                                d.type = "SWITCH",
                                d.flag = "ZHI",
                                d.part.cp = "QIAN",
                                d.part.rp = ""
                        } else if ("WAN" == p.part.rp) {
                            var d = Utils.copy(s);
                            d.index = c,
                                d.type = "SWITCH",
                                d.flag = "WAN",
                                d.part.cp = "QIAN",
                                d.part.rp = ""
                        }
                        t.push(d)
                    } else if ("SIGNAL" == e[c].category) if ("DIAO" == e[c].type.match("DIAO")) {
                        if (0 == e[c].bingZhi && 0 == e[c].chaZhi) {
                            var d = Utils.copy(s);
                            if (d.index = c, d.type = "SIGNAL", t.push(d), p.aspect == e[c].aspect) o(t, "DIAO", h),
                                a(t),
                                h++;
                            else if (e[c].dzzd) {
                                if ( - 1 != e[c].jg) {
                                    var d = Utils.copy(s);
                                    d.index = Model.getIndexByID(e[c].jg),
                                        d.type = "TRACK",
                                        t.push(d)
                                }
                                o(t, "DIAO", h),
                                    a(t),
                                    h++
                            } else if (i(e[c]) && p.aspect != e[c].aspect) {
                                var d = Utils.copy(s);
                                d.index = c,
                                    d.type = "SIGNAL",
                                    t.push(d);
                                var d = Utils.copy(s);
                                d.index = Model.getIndexByID(e[c].jg),
                                    d.type = "TRACK",
                                    t.push(d),
                                    o(t, "DIAO", h),
                                    a(t),
                                    h++
                            } else if (n(e[c]) && p.aspect != e[c].aspect) {
                                var d = Utils.copy(s);
                                if (d.index = c, d.type = "SIGNAL", t.push(d), -1 != e[c].jg) {
                                    var d = Utils.copy(s);
                                    d.index = Model.getIndexByID(e[c].jg),
                                        d.type = "TRACK",
                                        t.push(d)
                                }
                                o(t, "DIAO", h),
                                    a(t),
                                    h++
                            } else d.flag = "BG"
                        } else if (e[c].bingZhi || e[c].chaZhi) {
                            var d = Utils.copy(s);
                            if (d.index = c, d.type = "SIGNAL", t.push(d), p.aspect != e[c].aspect) {
                                if (e[c].chaZhi && -1 != e[c].jg) {
                                    var d = Utils.copy(s);
                                    d.index = Model.getIndexByID(e[c].jg),
                                        d.type = "TRACK",
                                        t.push(d)
                                }
                                o(t, "DIAO", h),
                                    a(t),
                                    h++
                            }
                        }
                    } else if ("LIE" == e[c].type.match("LIE")) {
                        for (var g = !1,
                                 u = 0; u < e[c].button.length; u++) if (("DBUTTON" == e[c].button[u] || "DZBUTTON" == e[c].button[u]) && p.aspect != e[c].aspect) {
                            g = !0;
                            var d = Utils.copy(s);
                            if (d.index = c, d.type = "SIGNAL", t.push(d), ("CZ" == e[c].signalType || "CZD" == e[c].signalType || "JL" === e[c].signalType || "TF" === e[c].signalType || "DZBUTTON" == e[c].button[u] && "JZ" === e[c].signalType) && -1 != e[c].jg) {
                                var d = Utils.copy(s);
                                d.index = Model.getIndexByID(e[c].jg),
                                    d.type = "TRACK",
                                    t.push(d)
                            }
                            o(t, "DIAO", h),
                                a(t),
                                h++;
                            break
                        }
                        g || a(t)
                    }
                }
            }
        }
        function n(e) {
            if ( - 1 != e.jg) {
                var t = Model.getIndexByID(e.jg);
                if ( - 1 != t && "TRACK" === Model.elements[t].category && ("WCQD" === Model.elements[t].trackType || "GD" === Model.elements[t].trackType)) return ! 0
            }
            return ! 1
        }
        function i(e) {
            if ("SIGNAL" === e.category) for (var t = !1,
                                                  n = 0; n < e.button.length; n++) if ("LZBUTTON" === e.button[n]) {
                if (t) return ! 0;
                t = !0
            } else if ("DBUTTON" === e.button[n]) {
                if (t) return ! 0;
                t = !0
            }
            return ! 1
        }
        function a(e) {
            for (var n = (Model.elements, !1); ! n;) if (e.length < 1) n = !0;
            else {
                var i = e[e.length - 1]; - 1 != i.index && "SWITCH" == i.type && "QIAN" == i.flag && "WAN" != i.part.cp ? (i.part.cp = "WAN", i.bg = !0, n = !0) : e.pop()
            }
        }
        function o(e, t, n) {
            for (var i = lsb.routateTable.length,
                     a = {
                         id: -1,
                         idTong: [],
                         number: -1,
                         throat: -1,
                         type: "",
                         buttons: [],
                         shapes: [],
                         aspect: [],
                         path: "",
                         startSignal: -1,
                         endSignal: -1,
                         routeType: "",
                         basicRoute: !1,
                         keySwitch: [],
                         group: -1,
                         bgpoints: [],
                         bgElements: [],
                         fhSwitch: [],
                         ddSwitch: [],
                         conflictingSiganl: [],
                         tracks: [],
                         faceConflictingLie: [],
                         faceConflictingDiao: []
                     },
                     o = {
                         index: -1,
                         statu: "default",
                         type: "",
                         bg: !1
                     },
                     s = 0; s < e.length; s++) {
                var r = Utils.copy(o);
                r.index = e[s].index,
                    r.type = e[s].type,
                    r.bg = e[s].bg,
                "SWITCH" == Model.elements[r.index].category && ("WAN" == e[s].flag ? r.statu = "FAN_WEI": "ZHI" == e[s].flag ? r.statu = "DING_WEI": "QIAN" == e[s].flag && ("ZHI" == e[s].part.cp ? r.statu = "DING_WEI": r.statu = "FAN_WEI")),
                    a.shapes.push(r)
            }
            a.type = t,
                lsb.routateTable[i] = a
        }
        e(),
            t()
    },
    findConflictinRoute: function() {},
    buildLSB: function() {
        try {
            lsb.routateTable.splice(0, lsb.routateTable.length),
                lsb.setDZSignalZD(),
                lsb.setSignalJG(),
                lsb.findRoute(),
                lsb.findAspect(),
                lsb.setRouteType(),
                lsb.setRouteBGPoint(),
                lsb.setRouteNumber(),
                lsb.setRoutePart(),
                lsb.setRouteButton(),
                lsb.setKeySwitch(),
                lsb.setSwitch(),
                lsb.findConflictingSignal(),
                lsb.setTrack(),
                lsb.setFaceConflicting(),
                lsb.findTongRoute(),
                lsb.setRoutesIndex(),
                lsb.getLsbStringData(),
                lsb.findAndSetOtherSignal()
        } catch(e) {
            showAlertInfo("出现搜索异常，请仔细检查对象属性设置：" + e)
        }
    },
    findAndSetOtherSignal: function() {
        for (var t, n, e = Model.elements,
                 i = $("#designer_canvas").children("canvas")[0], a = 0; a < e.length; a++) if ("TRACK" == e[a].category && !(e[a].chaZhi || e[a].bingZhi || "WCQD" != e[a].trackType && "GD" != e[a].trackType)) {
            t = e[a].component.point[0],
                n = e[a].component.point[1];
            var o = i.getContext("2d");
            o.beginPath(),
                o.rect(t.x - 1.5 * e[a].lineWidth, t.y - 5 * e[a].lineWidth, 3 * e[a].lineWidth, 10 * e[a].lineWidth);
            var s = [];
            for (j = 0; j < e.length; j++)"SIGNAL" == e[j].category && (o.isPointInPath(e[j].component.base[0].x, e[j].component.base[0].y) || o.isPointInPath(e[j].component.base[1].x, e[j].component.base[1].y)) && s.push(j);
            o.beginPath(),
                o.rect(n.x - 1.5 * e[a].lineWidth, n.y - 5 * e[a].lineWidth, 3 * e[a].lineWidth, 10 * e[a].lineWidth),
                o.stroke();
            var r = [];
            for (j = 0; j < e.length; j++)"SIGNAL" == e[j].category && (o.isPointInPath(e[j].component.base[0].x, e[j].component.base[0].y) || o.isPointInPath(e[j].component.base[1].x, e[j].component.base[1].y)) && r.push(j);
            if (s.length > 0 && r.length > 0) {
                if (e[s[0]].aspect == e[r[0]].aspect) continue;
                e[s[0]].otherSignal = e[r[0]].id,
                    e[r[0]].otherSignal = e[s[0]].id
            }
        }
    },
    setRoutesIndex: function() {
        for (var e = 0,
                 t = 0; t < lsb.routateTable.length; t++) lsb.routateTable[t].id = e++
    },
    findTongRoute: function() {
        function h(e) {
            for (var t = lsb.routateTable,
                     n = 0; n < t.length; n++) if (t[n].number == e) return n;
            return - 1
        }
        function p(e) {
            for (var t = 0; t < lsb.routateTable.length;) {
                if (lsb.routateTable[t].throat == e.throat) {
                    lsb.routateTable.splice(t, 0, e);
                    break
                }
                t++
            }
        }
        function c(e, t, n) {
            for (var i = lsb.routateTable,
                     a = 0; a < i.length; a++) if ("LIE" == i[a].type && i[a].throat == e) {
                if (n) {
                    if (i[a].shapes[i[a].shapes.length - 1].index != t) continue
                } else if (i[a].shapes[0].index != t) continue;
                for (var o = !1,
                         s = 0; s < i[a].shapes.length; s++) if ("SWITCH" == i[a].shapes[s].type && "FAN_WEI" == i[a].shapes[s].statu) {
                    o = !0;
                    break
                }
                if (!o) return i[a].number
            }
            return - 1
        }
        function d(e, t, n, i) {
            var a = {
                    id: -1,
                    idTong: [],
                    number: -1,
                    throat: -1,
                    type: "",
                    buttons: [],
                    shapes: [],
                    aspect: [],
                    path: "",
                    startSignal: -1,
                    endSignal: -1,
                    routeType: "",
                    basicRoute: !1,
                    keySwitch: [],
                    group: -2,
                    bgpoints: [],
                    bgElements: [],
                    fhSwitch: [],
                    ddSwitch: [],
                    conflictingSiganl: [],
                    tracks: [],
                    switches: [],
                    faceConflictingLie: [],
                    faceConflictingDiao: []
                },
                o = lsb.routateTable;
            a.throat = e,
                a.number = o[n].number + "/" + o[i].number,
                a.idTong[0] = o[n].id,
                a.idTong[1] = o[i].id,
                a.type = "TONG",
                a.buttons[0] = Model.getNameByID(o[n].shapes[0].index) + "TA",
                a.buttons[1] = o[i].buttons[o[i].buttons.length - 1];
            for (var s = 0; s < o[n].shapes.length; s++) a.shapes.push(o[n].shapes[s]);
            for (var s = 0; s < o[i].shapes.length; s++) a.shapes.push(o[i].shapes[s]);
            for (a.aspect[0] = "列车进路", a.aspect[1] = "", a.aspect[2] = "通过进路", a.path = "经" + t + "通过", a.routeType = 1, a.startSignal = o[n].startSignal, s = 0; s < o[n].shapes.length; s++)"SWITCH" == o[n].shapes[s].type && a.switches.push(o[n].shapes[s]);
            for (s = 0; s < o[i].shapes.length; s++)"SWITCH" == o[i].shapes[s].type && a.switches.push(o[i].shapes[s]);
            for (s = 0; s < o[n].fhSwitch.length; s++) a.fhSwitch.push(o[n].fhSwitch[s]);
            for (s = 0; s < o[i].fhSwitch.length; s++) a.fhSwitch.push(o[i].fhSwitch[s]);
            for (s = 0; s < o[n].ddSwitch.length; s++) a.ddSwitch.push(o[n].ddSwitch[s]);
            for (s = 0; s < o[i].ddSwitch.length; s++) a.ddSwitch.push(o[i].ddSwitch[s]);
            for (s = 0; s < o[n].conflictingSiganl.length; s++) a.conflictingSiganl.push(o[n].conflictingSiganl[s]);
            for (s = 0; s < o[i].conflictingSiganl.length; s++) a.conflictingSiganl.push(o[i].conflictingSiganl[s]);
            for (s = 0; s < o[n].tracks.length; s++) a.tracks.push(o[n].tracks[s]);
            for (s = 0; s < o[i].tracks.length; s++) a.tracks.push(o[i].tracks[s]);
            return a
        }
        for (var e = Model.elements,
                 t = 0; t < e.length; t++) if ("TRACK" == e[t].category && "GD" == e[t].trackType && -1 != e[t].qianNode && -1 != e[t].houNode && "SIGNAL" == Model.getNodeByID(Model.getIndexByID(e[t].qianNode)).category && "SIGNAL" == Model.getNodeByID(Model.getIndexByID(e[t].houNode)).category && "CZ" == Model.getNodeByID(Model.getIndexByID(e[t].qianNode)).signalType.match("CZ") && "CZ" == Model.getNodeByID(Model.getIndexByID(e[t].houNode)).signalType.match("CZ")) {
            var n = Model.getNodeByID(Model.getIndexByID(e[t].qianNode)).throat,
                i = Model.getNodeByID(Model.getIndexByID(e[t].houNode)).throat,
                a = c(n, t, !0),
                o = c(i, Model.getIndexByID(e[t].houNode), !1),
                s = -1,
                r = -1;
            if (a = h(a), o = h(o), -1 != a && -1 != o) {
                if ("SIGNAL" == Model.getNodeByID(lsb.routateTable[a].shapes[0].index).category && "JZ" == Model.getNodeByID(lsb.routateTable[a].shapes[0].index).signalType) {
                    for (var l = !1,
                             f = 0; f < Model.getNodeByID(lsb.routateTable[a].shapes[0].index).button.length; f++) if ("TGBUTTON" == Model.getNodeByID(lsb.routateTable[a].shapes[0].index).button[f]) {
                        l = !0;
                        break
                    }
                    if (!l) return;
                    s = d(n, e[t].name, a, o)
                }
                if ( - 1 != s && p(s), a = c(i, t, !0), o = c(n, Model.getIndexByID(e[t].qianNode), !1), a = h(a), o = h(o), -1 != a && -1 != o) {
                    if ("SIGNAL" == Model.getNodeByID(lsb.routateTable[a].shapes[0].index).category && "JZ" == Model.getNodeByID(lsb.routateTable[a].shapes[0].index).signalType) {
                        for (var l = !1,
                                 f = 0; f < Model.getNodeByID(lsb.routateTable[a].shapes[0].index).button.length; f++) if ("TGBUTTON" == Model.getNodeByID(lsb.routateTable[a].shapes[0].index).button[f]) {
                            l = !0;
                            break
                        }
                        if (!l) continue;
                        r = d(i, e[t].name, a, o)
                    } - 1 != r && p(r)
                }
            }
        }
    },
    setFaceConflicting: function() {
        for (var e = lsb.routateTable,
                 t = Model.elements,
                 n = 0; n < e.length; n++) {
            var i = e[n].shapes[e[n].shapes.length - 1].index,
                a = Model.getNodeByID(i); - 1 != a && "TRACK" == a.category && "GD" == a.trackType && ("LIE" == e[n].type ? (e[n].faceConflictingLie.push(t[e[n].shapes[e[n].shapes.length - 1].index].name), e[n].faceConflictingDiao.push(t[e[n].shapes[e[n].shapes.length - 1].index].name)) : e[n].faceConflictingLie.push(t[e[n].shapes[e[n].shapes.length - 1].index].name))
        }
    },
    setTrack: function() {
        function h(e, n) {
            if ( - 1 === n) return ! 1;
            for (var i = 0; i < e.shapes.length; i++) if (t[e.shapes[i].index].id === n.id) return ! 0;
            return ! 1
        }
        function p(e, n) {
            if ("SWITCH" !== e.category) return - 1;
            var i = "",
                a = e.qinXian;
            "JIAN" == a ? i = e.component.chaJian[0].x > e.component.chaJian[1].x ? "XX": "SX": "ZHI" == a ? i = e.component.chaZhi[0].x > e.component.chaZhi[1].x ? "SX": "XX": "WAN" == a && (i = e.component.chaWan[0].x > e.component.chaWan[1].x ? "SX": "XX");
            for (var o = !1,
                     s = n; ! o;) {
                var r = {
                    cp: "",
                    rp: ""
                };
                r.cp = a;
                var l = lsb.getNextNode(s, i, r);
                if (l = Model.getIndexByID(l), -1 == l) o = !0;
                else {
                    if ("SWITCH" == t[l].category) return t[l];
                    if ("TRACK" == t[l].category && t[l].name != t[n].track) return t[l];
                    s = l
                }
            }
            return - 1
        }
        function d(e, t) {
            for (var n = 0; n < t.length; n++) if (t[n].tg == e) return ! 0;
            return ! 1
        }
        for (var e = lsb.routateTable,
                 t = Model.elements,
                 n = {
                     tg: -1,
                     tw: -1,
                     tws: -1
                 },
                 i = 0; i < e.length; i++) for (var a = 0; a < e[i].shapes.length; a++) {
            if ("SXDZA" === e[i].buttons[1] && "D12A" === e[i].buttons[0]);
            if ("TRACK" == e[i].shapes[a].type) {
                if (!d(t[e[i].shapes[a].index].name, e[i].tracks)) if ("DIAO" == e[i].type) if (a == e[i].shapes.length - 1) {
                    if ("GD" != t[e[i].shapes[a].index].trackType) {
                        var s = Utils.copy(n);
                        s.tg = t[e[i].shapes[a].index].name,
                            e[i].tracks.push(s)
                    }
                } else {
                    var s = Utils.copy(n);
                    s.tg = t[e[i].shapes[a].index].name,
                        e[i].tracks.push(s)
                } else {
                    var s = Utils.copy(n);
                    s.tg = t[e[i].shapes[a].index].name,
                        e[i].tracks.push(s)
                }
            } else if ("SWITCH" == e[i].shapes[a].type) {
                if (!d(t[e[i].shapes[a].index].track, e[i].tracks)) {
                    var s = Utils.copy(n);
                    s.tg = t[e[i].shapes[a].index].track,
                        e[i].tracks.push(s)
                }
                if ("DING_WEI" == e[i].shapes[a].statu && "WAN" == t[e[i].shapes[a].index].qinXian || "FAN_WEI" == e[i].shapes[a].statu && "ZHI" == t[e[i].shapes[a].index].qinXian) {
                    var r = p(t[e[i].shapes[a].index], e[i].shapes[a].index);
                    if (h(e[i], r)) continue;
                    if ( - 1 === r) continue;
                    if ("SWITCH" === r.category) {
                        var s = Utils.copy(n);
                        s.tg = r.track,
                            "JIAN" === r.qinXian ? ( - 1 === r.otherDoubleCrossover ? s.tw = -1 : (s.tw = Model.getNodeByID(Model.getIndexByID(r.zhiNode)), s.tws = "DING_WEI"), e[i].tracks.push(s)) : "ZHI" === r.qinXian ? ( - 1 === r.otherDoubleCrossover ? (s.tw = r, s.tws = "DING_WEI") : r.zhiNode === t[e[i].shapes[a].index].id || r.otherDoubleCrossover === t[e[i].shapes[a].index].id || Model.getNodeByID(Model.getIndexByID(r.otherDoubleCrossover)).otherSwitch === t[e[i].shapes[a].index].id ? s.tw = -1 : (s.tw = r, s.tws = "DING_WEI"), e[i].tracks.push(s)) : "WAN" === r.qinXian && (s.tw = r, s.tws = "FAN_WEI", e[i].tracks.push(s))
                    } else if ("TRACK" === r.category) {
                        var s = Utils.copy(n);
                        s.tg = r.name,
                            e[i].tracks.push(s)
                    }
                } else if ("DING_WEI" == e[i].shapes[a].statu && "ZHI" == t[e[i].shapes[a].index].qinXian) {
                    for (var l = -1,
                             f = e[i].shapes.length - 1; f > 0; f--) if ("TRACK" === t[e[i].shapes[f].index].category || "SWITCH" === t[e[i].shapes[f].index].category) {
                        l = f;
                        break
                    }
                    if ( - 1 === l) continue;
                    if (t[e[i].shapes[a].index].id === t[e[i].shapes[l].index].id) {
                        var r = p(t[e[i].shapes[a].index], e[i].shapes[a].index);
                        if ( - 1 !== r && "SWITCH" === r.category) {
                            if (h(e[i], r)) continue;
                            if ("ZHI" === r.qinXian && -1 !== r.otherDoubleCrossover && (r.zhiNode === t[e[i].shapes[a].index].id || r.otherDoubleCrossover === t[e[i].shapes[a].index].id || Model.getNodeByID(Model.getIndexByID(r.otherDoubleCrossover)).otherSwitch === t[e[i].shapes[a].index].id)) {
                                var s = Utils.copy(n);
                                s.tg = r.track,
                                    s.tw = r,
                                    s.tws = "FAN_WEI",
                                    e[i].tracks.push(s)
                            }
                        }
                    }
                }
            }
        }
    },
    findConflictingSignal: function() {
        function s(t, n) {
            for (var i = f(t, n), a = {
                    sg: -1,
                    sw: -1,
                    type: -1
                },
                     o = 0; o < i.length; o++) {
                var s = r(t, i[o], n);
                if (0 != s.length) if (1 == s.length) {
                    var l = Utils.copy(a);
                    l.sg = i[o],
                        l.type = t,
                        e[n].conflictingSiganl.push(l)
                } else {
                    for (var p = !0,
                             c = [], d = [], g = 0; g < s.length; g++) h(n, s[g]) ? c.push(s[g]) : (p = !1, d.push(s[g]));
                    if (p) {
                        var l = Utils.copy(a);
                        l.sg = i[o],
                            l.type = t,
                            e[n].conflictingSiganl.push(l)
                    } else if (d.length > 0 && c.length > 0) for (var u = !1,
                                                                      v = 0; v < e[c[0]].shapes.length; v++) if ("SWITCH" == e[c[0]].shapes[v].type) {
                        if (u) break;
                        for (var b = 0; b < e[d[0]].shapes.length; b++) if ("SWITCH" == e[d[0]].shapes[b].type && e[c[0]].shapes[v].index == e[d[0]].shapes[b].index && e[c[0]].shapes[v].statu != e[d[0]].shapes[b].statu) {
                            var l = Utils.copy(a);
                            l.sg = i[o],
                                l.sw = e[c[0]].shapes[v],
                                l.type = t,
                                e[n].conflictingSiganl.push(l),
                                u = !0;
                            break
                        }
                    }
                }
            }
        }
        function r(t, n, i) {
            for (var a = l(t, n), o = [], s = 0; s < e[i].shapes.length; s++) if ("SWITCH" == e[i].shapes[s].type) for (var r = 0; r < a.length; r++) if ( - 1 != a[r]) for (var f = 0; f < e[a[r]].shapes.length; f++) if ("SWITCH" == e[a[r]].shapes[f].type && e[a[r]].shapes[f].index == e[i].shapes[s].index && e[a[r]].shapes[f].statu != e[i].shapes[s].statu) {
                a[r] = -1;
                break
            }
            for (r = 0, s = 0; s < a.length; s++) - 1 != a[s] && (o[r] = a[s], r++);
            return o
        }
        function l(t, n) {
            for (var i = [], a = 0; a < e.length; a++) e[a].type == t && e[a].shapes[0].index == n.index && i.push(a);
            return i
        }
        function f(t, n) {
            for (var i = [], a = 0; a < e.length; a++) if (a != n && e[a].type == t && h(n, a)) {
                for (var o = !1,
                         s = 0; s < i.length; s++) if (e[a].shapes[0].index == i[s].index) {
                    o = !0;
                    break
                }
                o || i.push(e[a].shapes[0])
            }
            return i
        }
        function h(t, n) {
            for (var i = 0; i < e[t].shapes.length; i++) {
                for (var a = !1,
                         o = 0; o < e[n].shapes.length; o++) if (e[t].shapes[i].index == e[n].shapes[o].index) {
                    a = !0;
                    break
                }
                if (!a) return ! 1
            }
            return ! 0
        }
        for (var e = lsb.routateTable,
                 t = Model.elements,
                 n = {
                     sg: -1,
                     sw: -1,
                     type: -1
                 },
                 i = 0; i < e.length; i++) if ("LIE" == e[i].type) {
            for (var a = 1; a < e[i].shapes.length; a++) if ("SIGNAL" == e[i].shapes[a].type) {
                var o = Utils.copy(n);
                o.sg = e[i].shapes[a],
                    o.type = "LIE",
                    e[i].conflictingSiganl.push(o)
            }
        } else if ("DIAO" == e[i].type) {
            for (var a = 1; a < e[i].shapes.length; a++) if ("SIGNAL" == e[i].shapes[a].type && t[e[i].shapes[0].index].aspect != t[e[i].shapes[a].index].aspect) {
                var o = Utils.copy(n);
                o.sg = e[i].shapes[a],
                    o.type = "DIAO",
                    e[i].conflictingSiganl.push(o)
            }
            s("LIE", i),
                s("DIAO", i)
        }
    },
    setSwitch: function() {
        function i() {
            for (var n = [], i = {
                    zdc: {
                        index: -1,
                        statu: "default",
                        type: "",
                        bg: !1
                    },
                    sdc: {
                        index: -1,
                        statu: "default",
                        type: "",
                        bg: !1
                    }
                },
                     s = 1; s < t.length; s++) {
                var r = t[s].zdc,
                    l = t[s].fhdc,
                    f = o(r, l);
                f && n.push(f)
            }
            for (s = 0; s < Model.elements.length; s++) if ("SWITCH" == Model.elements[s].category && -1 != Model.elements[s].otherSwitch && -1 != Model.elements[s].otherDoubleCrossover) {
                var h = s,
                    c = (Model.getIndexByID(Model.elements[s].otherSwitch), Model.getIndexByID(Model.elements[s].otherDoubleCrossover));
                Model.getIndexByID(Model.elements[c].otherSwitch);
                if (!a(n, h)) {
                    var g = Utils.copy(i);
                    g.zdc.index = h,
                        g.zdc.statu = "FAN_WEI",
                        g.sdc.index = c,
                        g.sdc.statu = "FAN_WEI",
                        n.push(g),
                        g = Utils.copy(i),
                        g.zdc.index = c,
                        g.zdc.statu = "FAN_WEI",
                        g.sdc.index = h,
                        g.sdc.statu = "FAN_WEI",
                        n.push(g)
                }
            }
            for (s = 0; s < n.length; s++) for (var u = 0; u < e.length; u++) for (var v = 0; v < e[u].shapes.length; v++) if ("SWITCH" == e[u].shapes[v].type) if (e[u].shapes[v].index == n[s].zdc.index && e[u].shapes[v].statu == n[s].zdc.statu) e[u].fhSwitch.push(n[s]);
            else {
                var b = Model.elements[n[s].zdc.index].otherSwitch; - 1 != b && b == e[u].shapes[v].index && e[u].shapes[v].statu == n[s].zdc.statu && e[u].fhSwitch.push(n[s])
            }
        }
        function a(e, t) {
            for (var n = 0; n < e.length; n++) {
                if (e[n].zdc.index == t) return ! 0;
                if ( - 1 != Model.elements[t].otherSwitch) {
                    var i = Model.getIndexByID(Model.elements[t].otherSwitch);
                    if (e[n].zdc.index == i) return ! 0
                }
            }
            return ! 1
        }
        function o(e, t) {
            var n = {
                    zdc: {
                        index: -1,
                        statu: "default",
                        type: "",
                        bg: !1
                    },
                    sdc: {
                        index: -1,
                        statu: "default",
                        type: "",
                        bg: !1
                    }
                },
                i = /[1-9]([0-9])*/g,
                a = e.match(i),
                o = t.match(i);
            if (a && o) {
                for (var s = -1,
                         r = -1,
                         l = 0; l < a.length; l++) if (s = Model.getNodeByName(a[l]), -1 == s) return ! 1;
                for (l = 0; l < o.length; l++) if (r = Model.getNodeByName(o[l]), -1 == r) return ! 1;
                return n.zdc.index = s,
                    n.sdc.index = r,
                    -1 != e.indexOf("(") ? n.zdc.statu = "FAN_WEI": n.zdc.statu = "DING_WEI",
                    -1 != t.indexOf("(") ? n.sdc.statu = "FAN_WEI": n.sdc.statu = "DING_WEI",
                    n
            }
        }
        function s() {
            for (var t = [], i = 1; i < n.length; i++) {
                var a = n[i].zdc,
                    s = n[i].dddc,
                    r = o(a, s);
                r && t.push(r)
            }
            for (i = 0; i < t.length; i++) for (var l = 0; l < e.length; l++) for (var f = 0; f < e[l].length; f++) if ("SWITCH" == e[l].shapes[f].type) if (e[l].shapes[f].index == t[i].zdc.index && e[l].shapes[f].statu == t[i].zdc.statu) e[l].fhSwitch.push(t[i].sdc);
            else {
                var h = Model.elements[t[i].zdc.index].otherSwitch; - 1 != h && h == e[l].shapes[f].index && e[l].shapes[f].statu == t[i].zdc.statu && e[l].fhSwitch.push(t[i].sdc)
            }
        }
        var e = lsb.routateTable,
            t = Model.fhSwitchTable,
            n = Model.ddSwitchTable;
        i(),
            s()
    },
    setKeySwitch: function() {
        var e = lsb.routateTable,
            t = {
                index: -1,
                statu: "",
                text: ""
            };
        for (i = 0; i < this.groupCnt; i++) {
            for (var n = [], a = 0; a < e.length; a++) e[a].group == i && n.push(e[a]);
            if (! (n.length <= 1)) {
                var o = [];
                for (a = 0; a < n.length; a++) for (var s = 0; s < n[a].bgpoints.length; s++) o.push(n[a].bgpoints[s]);
                for (a = 0; a < n.length; a++) {
                    var r = !1;
                    for (s = 0; s < n[a].bgpoints.length; s++) {
                        for (var l = !1,
                                 f = 0; f < n.length; f++) if (a != f) for (var h = 0; h < n[f].bgpoints.length; h++) if (n[a].bgpoints[s].index == n[f].bgpoints[h].index && n[a].bgpoints[s].statu == n[f].bgpoints[h].statu) {
                            l = !0;
                            break
                        }
                        if (0 == l) {
                            r = !0;
                            var p = Utils.copy(t);
                            p.index = n[a].bgpoints[s].index,
                                p.statu = n[a].bgpoints[s].statu,
                                p.text = lsb.switchName(n[a].bgpoints[s].index, n[a].bgpoints[s].statu),
                                n[a].keySwitch.push(p);
                            break
                        }
                    }
                    if (0 == r) for (s = 0; s < n[a].bgpoints.length; s++) {
                        var p = Utils.copy(t);
                        p.index = n[a].bgpoints[s].index,
                            p.statu = n[a].bgpoints[s].statu,
                            p.text = lsb.switchName(n[a].bgpoints[s].index, n[a].bgpoints[s].statu),
                            n[a].keySwitch.push(p)
                    }
                }
            }
        }
    },
    switchName: function(e, t) {
        var n = Model.elements;
        if (e > n.length || 0 > e) return ! 1;
        var i = n[e];
        if ( - 1 == i.otherSwitch) return "FAN_WEI" == t ? "(" + i.name + ")": i.name;
        var a = i,
            o = n[Model.getIndexByID(i.otherSwitch)],
            s = "";
        return s = a.name < o.name ? a.name + "/" + o.name: o.name + "/" + a.name,
            "FAN_WEI" == t ? "(" + s + ")": s
    },
    setRouteButton: function() {
        for (var e = lsb.routateTable,
                 t = Model.elements,
                 n = 0; n < e.length; n++) {
            var i = 0;
            if ("LIE" == e[n].type) {
                "DIAO" == t[e[n].shapes[0].index].type.match("DIAO") ? e[n].buttons[i++] = t[e[n].shapes[0].index].name + "A": e[n].buttons[i++] = t[e[n].shapes[0].index].name + "LA";
                for (var a = 0; a < e[n].bgElements.length; a++)"SIGNAL" == e[n].bgElements[a].category ? e[n].buttons[i++] = e[n].bgElements[a].name + "A": e[n].buttons[i++] = e[n].bgElements[a].extraButton.name;
                var o = e[n].shapes.length - 1;
                "SIGNAL" != e[n].shapes[o].type && (o -= 1);
                var s = !1;
                for (a = 0; a < t[e[n].shapes[o].index].button.length; a++) if ("LZBUTTON" == t[e[n].shapes[o].index].button[a].match("LZBUTTON")) {
                    s = !0;
                    break
                }
                s ? e[n].buttons[i++] = t[e[n].shapes[o].index].name + "LZA": "DIAO" == t[e[n].shapes[o].index].type.match("DIAO") ? e[n].buttons[i++] = t[e[n].shapes[o].index].name + "A": e[n].buttons[i++] = t[e[n].shapes[o].index].name + "LA"
            } else if ("DIAO" == e[n].type) {
                "DIAO" == t[e[n].shapes[0].index].type.match("DIAO") ? e[n].buttons[i++] = t[e[n].shapes[0].index].name + "A": e[n].buttons[i++] = t[e[n].shapes[0].index].name + "DA";
                for (var a = 0; a < e[n].bgElements.length; a++)"SIGNAL" == e[n].bgElements[a].type ? e[n].buttons[i++] = e[n].bgElements[a].name: e[n].buttons[i++] = e[n].bgElements[a].extraButton.name;
                var o = e[n].shapes.length - 1;
                if ("SIGNAL" != e[n].shapes[o].type && (o -= 1), "DIAO" == t[e[n].shapes[o].index].type.match("DIAO")) e[n].buttons[i++] = t[e[n].shapes[o].index].name + "A";
                else {
                    for (var s = !1,
                             a = 0; a < t[e[n].shapes[o].index].button.length; a++) if ("DZBUTTON" == t[e[n].shapes[o].index].button[a]) {
                        s = !0;
                        break
                    }
                    s ? e[n].buttons[i++] = t[e[n].shapes[o].index].name + "DZA": e[n].buttons[i++] = t[e[n].shapes[o].index].name + "DA"
                }
            } else "TONG" == e[n].type
        }
    },
    setRouteBGPoint: function() {
        function l(e, t) {
            for (var n = e[t], i = !1, a = 0; a < n.bgpoints.length; a++) {
                for (var o = -1,
                         s = 0; s < n.shapes.length; s++) if (n.shapes[s].index == n.bgpoints[a].index) {
                    o = s;
                    break
                }
                for (var s = o + 1; s < n.shapes.length && !d(n, n.shapes[s].index); s++) if ("SIGNAL" == n.shapes[s].type && !c(n, n.shapes[s].index) && p(n, s)) {
                    for (var r = !1,
                             l = 0; l < e.length; l++) if (l != t) {
                        if (r) break;
                        for (var g = 0; g < e[l].shapes.length; g++) if (e[l].shapes[g].index == n.shapes[s].index) {
                            r = !0;
                            break
                        }
                    }
                    if (!r) {
                        h(e, t, n, s),
                            i = !0;
                        break
                    }
                }
            }
            if (!i) for (var a = 0; a < n.bgpoints.length; a++) if ("FAN_WEI" == n.bgpoints[a].statu) {
                for (var o = -1,
                         s = 0; s < n.shapes.length; s++) if (n.shapes[s].index == n.bgpoints[a].index) {
                    o = s;
                    break
                }
                for (var s = o + 1; s < n.shapes.length && !d(n, n.shapes[s].index); s++) {
                    if ("SWITCH" == n.shapes[s].type && -1 != Model.elements[n.shapes[s].index].extraButton.id && f(n, s)) {
                        if (c(n, n.shapes[s].index)) continue;
                        n.bgElements.push(Model.elements[n.shapes[s].index]);
                        break
                    }
                    if ("SIGNAL" == n.shapes[s].type && !c(n, n.shapes[s].index) && p(n, s)) {
                        h(e, t, n, s),
                            i = !0;
                        break
                    }
                }
            }
        }
        function f(e, t) {
            if ("DING_WEI" == e.shapes[t].statu) {
                if ("CX" == Model.elements[e.shapes[t].index].extraButton.pos || "CJ" == Model.elements[e.shapes[t].index].extraButton.pos || "CZ" == Model.elements[e.shapes[t].index].extraButton.pos) return ! 0
            } else if ("CX" == Model.elements[e.shapes[t].index].extraButton.pos || "CJ" == Model.elements[e.shapes[t].index].extraButton.pos || "CW" == Model.elements[e.shapes[t].index].extraButton.pos) return ! 0;
            return ! 1
        }
        function h(e, t, n, i) {
            if (0 == n.bgElements.length) n.bgElements.push(Model.elements[n.shapes[i].index]);
            else {
                for (var a = -1,
                         o = 0; o < n.shapes.length; o++) if (Model.getIDByIndex(n.shapes[o].index) == n.bgElements[n.bgElements.length - 1]) {
                    a = o;
                    break
                }
                if ( - 1 != a && i > a) for (o = a + 1; i > o; o++)"SWITCH" == n.shapes[o].type && "FAN_WEI" == n.shapes[o].statu && g(e, t, n.shapes[o].index) && n.bgElements.push(Model.elements[n.shapes[i].index])
            }
        }
        function p(e, t) {
            var n = Model.elements[e.shapes[t].index];
            if ("DIAO" == e.type) {
                if ("SIGNAL" == n.category && "DIAO" == n.signalType.match("DIAO")) {
                    if (n.bingZhi || n.chaZhi) return ! 1;
                    if (n.aspect != Model.elements[e.shapes[0].index].aspect) return ! 0
                }
            } else if ("LIE" == e.type && "SIGNAL" == n.category && "DIAO" == n.type.match("DIAO")) return ! 0;
            return ! 1
        }
        function c(e, t) {
            if ("SWITCH" == Model.elements[t].category) {
                for (var n = Model.elements[t].extraButton.name, i = 0; i < e.bgElements.length; i++) if ("SWITCH" == e.bgElements[i].category && e.bgElements[i].extraButton.name == n) return ! 0
            } else for (var i = 0; i < e.bgElements.length; i++) if (Model.getIndexByID(e.bgElements[i].id) == t) return ! 0;
            return ! 1
        }
        function d(e, t) {
            if ("SIGNAL" == e.shapes[e.shapes.length - 1].type) {
                if (e.shapes[e.shapes.length - 1].index == t) return ! 0
            } else if (e.shapes[e.shapes.length - 2].index == t) return ! 0;
            return ! 1
        }
        function g(e, t, n) {
            for (var i = !1,
                     a = !1,
                     o = 0; o < e.length; o++) for (var s = 0; s < e[o].shapes.length; s++) if (e[o].shapes[s].index == n && ("DING_WEI" == e[o].shapes[s].statu ? i = !0 : "FAN_WEI" == e[o].shapes[s].statu && (a = !0), i && a)) return ! 0;
            return ! 1
        }
        var e = lsb.routateTable;
        for (i = 0; i < this.groupCnt; i++) {
            for (var a = [], o = 0; o < e.length; o++) e[o].group == i && a.push(e[o]);
            if (! (a.length <= 1)) {
                var s = [];
                for (o = 0; o < a.length; o++) {
                    for (var r = 0; r < a[o].shapes.length; r++)"SWITCH" == a[o].shapes[r].type && g(a, o, a[o].shapes[r].index) && (s.push(a[o].shapes[r]), a[o].bgpoints.push(a[o].shapes[r]));
                    a[o].basicRoute || l(a, o)
                }
            }
        }
    },
    setRouteType: function() {
        function d() {
            for (var e = lsb.routateTable,
                     t = Model.elements,
                     n = 0; n < e.length; n++) for (e[n].startSignal = e[n].shapes[0].index, a = e[n].shapes.length - 1; a >= 0; a--) {
                var i = t[e[n].shapes[a].index];
                if ("SIGNAL" == i.category) {
                    e[n].endSignal = a;
                    break
                }
            }
        }
        var e = lsb.routateTable;
        d();
        for (var t = -1,
                 n = 0; n < e.length; n++) {
            var i = [];
            i[0] = e[n],
                t++;
            for (var a = 0; a < e.length; a++) n != a && e[n].startSignal == e[a].startSignal && e[n].endSignal == e[a].endSignal && e[n].type == e[a].type && i.push(e[a]);
            var o = !1;
            for (a = 0; a < i.length; a++) if (i[a].basicRoute) {
                o = !0;
                break
            }
            if (!o) {
                if (1 == i.length) i[0].basicRoute = !0;
                else {
                    for (var s = [], r = {
                            fanweip: -1,
                            cntdingwei: 0,
                            basic: !0
                        },
                             a = 0; a < i.length; a++) {
                        s[a] = Utils.copy(r);
                        for (var l = 0; l < i[a].shapes.length; l++)"SWITCH" == i[a].shapes[l].type && ("DING_WEI" == i[a].shapes[l].statu ? s[a].cntdingwei += 1 : ( - 1 == s[a].fanweip && (s[a].fanweip = l), s[a].basic = !1))
                    }
                    var o = !1;
                    for (a = 0; a < s.length; a++) if (s[a].basic) {
                        i[a].basicRoute = !0,
                            o = !0;
                        break
                    }
                    if (!o) {
                        var f = 0,
                            h = !0;
                        for (a = 1; a < s.length; a++) s[f].cntdingwei < s[a].cntdingwei ? f = a: s[f].cntdingwei == s[a].cntdingwei && (h = !1);
                        h && (i[f].basicRoute = !0, o = !0)
                    }
                    if (!o) {
                        var f = 0;
                        for (a = 1; a < s.length; a++) s[f].fanweip > s[a].fanweip && (f = a);
                        i[f].basicRoute = !0
                    }
                }
                var p = 1;
                for (a = 0; a < i.length; a++) i[a].basicRoute && (i[a].routeType = p++, i[a].group = t);
                for (a = 0; a < i.length; a++) i[a].basicRoute || (i[a].routeType = p++, i[a].group = t)
            }
        }
        e.sort(function(e, t) {
            return e.group - t.group
        });
        var c = [];
        for (n = 0; t >= n; n++) {
            var i = [];
            for (a = 0; a < e.length; a++) e[a].group == n && i.push(e[a]);
            for (i.length > 1 && i.sort(function(e, t) {
                return e.routeType - t.routeType
            }), a = 0; a < i.length; a++) c.push(Utils.copy(i[a]))
        }
        lsb.routateTable.splice(0, lsb.routateTable.length),
            lsb.routateTable = c,
            this.groupCnt = t + 1
    },
    setRoutePart: function() {
        for (var e = lsb.routateTable,
                 t = Model.elements,
                 n = 0; n < e.length; n++) if ("DIAO" == e[n].type) for (var i = e[n].shapes.length - 1; i > 0; i--) {
            var a = t[e[n].shapes[i].index],
                o = t[e[n].shapes[0].index];
            if (a) if ("TRACK" == a.category) {
                if ("GD" == a.trackType) {
                    e[n].path = "至" + a.name + "股道";
                    break
                }
                if ("WCQD" == a.trackType) {
                    if ( - 1 == a.qianNode || -1 == a.houNode) {
                        var s = a.qianNode; - 1 == a.qianNode && (s = a.houNode),
                            e[n].path = "向" + Model.getNameByID(Model.getIndexByID(s));
                        break
                    }
                    var r, l;
                    if (r = t[Model.getIndexByID(a.qianNode)], l = t[Model.getIndexByID(a.houNode)], "SIGNAL" == r.category && "JZ" == r.signalType) {
                        e[n].path = "向" + l.name;
                        break
                    }
                    if ("SIGNAL" == l.category && "JZ" == l.signalType) {
                        e[n].path = "向" + r.name;
                        break
                    }
                }
            } else if ("SIGNAL" == a.category) {
                if ("DIAO" == a.type.match("DIAO")) a.bingZhi || a.chaZhi ? a.aspect == o.aspect ? e[n].path = "至" + a.name: e[n].path = "至" + Model.getNameByID(Model.getIndexByID(a.otherSignal)) : a.aspect == o.aspect && (e[n].path = "至" + a.name);
                else for (var f = 0; f < a.button.length; f++)"DZBUTTON" == a.button[f] && (e[n].path = "至" + a.name + "进站信号机");
                break
            }
        } else if ("LIE" == e[n].type) {
            if ("接车进路" == e[n].aspect[2]) {
                var a = t[e[n].shapes[e[n].shapes.length - 1].index];
                "TRACK" == a.category && "GD" == a.trackType && (e[n].path = "至" + a.name + "股道")
            } else if ("发车进路" == e[n].aspect[2]) {
                var a = t[e[n].shapes[0].index]; - 1 != a.jg && (a = Model.getNodeByID(Model.getIndexByID(a.jg)), a && "TRACK" == a.category && "GD" == a.trackType && (e[n].path = "由" + a.name + "股道")),
                "SIGNAL" == a.category && "JL" == a.signalType && (e[n].path = "由" + a.name + "信号机")
            }
        } else "TONG" == e[n].type
    },
    setRouteNumber: function() {
        var e = lsb.routateTable,
            t = Model.elements,
            n = [],
            i = [],
            a = 1;
        temp = -1;
        for (var o = 0; o < e.length; o++) if (e[o].throat = Model.getNodeByID(e[o].shapes[0].index).throat, temp != e[o].throat) {
            for (var s = !1,
                     r = 0; r < i.length; r++) if (i[r] == e[o].throat) {
                s = !0;
                break
            }
            s || (temp = e[o].throat, i.push(temp))
        }
        for (var l = 0; l < i.length; l++) {
            for (var f = [], h = [], p = 0; p < t.length; p++) t[p].throat == i[l] && "SIGNAL" == t[p].category && f.push(t[p]);
            for (var c = 0; c < e.length; c++) e[c].throat == i[l] && h.push(e[c]);
            for (var d = f,
                     g = h,
                     u = [], o = 0; o < d.length; o++) if ("SIGNAL" == d[o].category && "JZ" == d[o].signalType) {
                for (var v = d[o].fangmian, b = !0, I = 0; I < u.length; I++) if (v == u[I]) {
                    b = !1;
                    break
                }
                b && u.push(d[o].fangmian)
            }
            for (var o = 0; o < u.length; o++) {
                for (var v = u[o], I = 0; I < g.length; I++)"TONG" == g[I].type && g[I].aspect[1] == v;
                for (var I = 0; I < g.length; I++)"LIE" == g[I].type && "接车进路" == g[I].aspect[2] && g[I].aspect[1] == v && (g[I].number = a, a++);
                for (var I = 0; I < g.length; I++)"LIE" == g[I].type && "发车进路" == g[I].aspect[2] && g[I].aspect[1] == v && (g[I].number = a, a++)
            }
            for (var o = 0; o < g.length; o++)"DIAO" == g[o].type && (g[o].number = a.toString(), a++);
            for (var o = 0; o < g.length; o++) - 1 == g[o].number && (g[o].number = a.toString(), a++);
            for (var y = 0; y < g.length; y++) n.push(Utils.copy(g[y]))
        }
        n.sort(function(e, t) {
            return e.number - t.number
        }),
            lsb.routateTable.splice(0, lsb.routateTable.length),
            lsb.routateTable = n
    },
    findAspect: function() {
        for (var e = lsb.routateTable,
                 t = Model.elements,
                 n = 0; n < e.length; n++) if ("DIAO" == e[n].type) {
            e[n].aspect[0] = "调车进路",
                e[n].aspect[1] = "由";
            var i = t[e[n].shapes[0].index];
            "LIE" == i.type.match("LIE") ? e[n].aspect[2] = i.name + "D": e[n].aspect[2] = i.name
        } else if ("LIE" == e[n].type) {
            e[n].aspect[0] = "列车进路";
            var i = t[e[n].shapes[0].index];
            "JZ" == i.signalType ? (e[n].aspect[1] = i.fangmian, e[n].aspect[2] = "接车进路") : "CZ" == i.signalType || "CZD" == i.signalType ? (e[n].aspect[2] = "发车进路", "undefined" == typeof t[e[n].shapes[e[n].shapes.length - 1].index].fangmian ? e[n].aspect[1] = "": e[n].aspect[1] = t[e[n].shapes[e[n].shapes.length - 1].index].fangmian) : "JL" == i.signalType && (e[n].aspect[1] = "", "SX" === i.aspect ? e[n].aspect[2] = "接车进路": e[n].aspect[2] = "发车进路")
        } else "TONG" == e[n].type
    },
    judgeAndSetSignalAspect: function() {
        for (var e = Model.elements,
                 t = 0; t < e.length; t++)"SIGNAL" == e[t].category && (e[t].component.base[0].x < e[t].component.firstLight[0].x ? e[t].aspect = "XX": e[t].aspect = "SX")
    },
    setDZSignalZD: function() {
        for (var e = Model.elements,
                 t = 0; t < e.length; t++) if ("SIGNAL" == e[t].category && !e[t].bingZhi && !e[t].chaZhi) if ( - 1 != e[t].qianNode) {
            var n = Model.getIndexByID(e[t].qianNode); - 1 != n && "TRACK" == e[n].category && "WCQD" == e[n].trackType && ("SX" == e[t].aspect ? e[n].component.point[0].x > e[t].component.firstLight[0].x && (e[t].jg = e[n].id, e[t].dzzd = !0) : "XX" == e[t].aspect && e[n].component.point[0].x < e[t].component.firstLight[0].x && (e[t].jg = e[n].id, e[t].dzzd = !0))
        } else if ( - 1 != e[t].houNode) {
            var n = Model.getIndexByID(e[t].houNode); - 1 != n && "TRACK" == e[n].category && "WCQD" == e[n].trackType && ("SX" == e[t].aspect ? e[n].component.point[0].x > e[t].component.firstLight[0].x && (e[t].jg = e[n].id, e[t].dzzd = !0) : "XX" == e[t].aspect && e[n].component.point[0].x < e[t].component.firstLight[0].x && (e[t].jg = e[n].id, e[t].dzzd = !0))
        }
    },
    setSignalJG: function() {
        function i(e, t, n) {
            if ( - 1 != n) {
                var i, a;
                if ("SWITCH" == e[n].category) i = e[n].component.chaJian[1],
                    a = e[n].component.chaJian[1];
                else {
                    if ("TRACK" != e[n].category) return - 1;
                    i = e[n].component.point[0],
                        a = e[n].component.point[1]
                }
                "XX" == e[t].aspect ? i.x < e[t].component.firstLight[0].x && a.x < e[t].component.firstLight[0].x && ("SWITCH" == e[n].category ? e[t].jg = e[n].id: "TRACK" == e[n].category && (e[t].jg = e[n].id)) : "SX" == e[t].aspect && i.x > e[t].component.firstLight[0].x && a.x > e[t].component.firstLight[0].x && ("SWITCH" == e[n].category ? e[t].jg = e[n].id: "TRACK" == e[n].category && (e[t].jg = e[n].id))
            }
        }
        for (var e = Model.elements,
                 t = 0; t < e.length; t++) if ("SIGNAL" == e[t].category && -1 == e[t].jg) {
            if ( - 1 != e[t].qianNode) {
                var n = Model.getIndexByID(e[t].qianNode);
                i(e, t, n)
            }
            if ( - 1 != e[t].houNode) {
                var n = Model.getIndexByID(e[t].houNode);
                i(e, t, n)
            }
        }
    },
    getNextNode: function(e, t, n) {
        var i = Model.elements;
        if ( - 1 == e) return - 1;
        if ("TRACK" == i[e].category || "SIGNAL" == i[e].category) {
            var a = -1;
            if ("XX" == t ? a = i[e].houNode: "SX" == t && (a = i[e].qianNode), -1 == a) return a;
            var o = Model.getIndexByID(a);
            return - 1 == o ? -1 : ("SWITCH" == i[o].category && (i[o].qianNode == i[e].id ? n.rp = "QIAN": i[o].zhiNode == i[e].id ? n.rp = "ZHI": i[o].wanNode == i[e].id && (n.rp = "WAN")), a)
        }
        if ("SWITCH" == i[e].category) {
            var s = -1;
            switch (n.cp) {
                case "":
                    return - 1;
                case "QIAN":
                    s = i[e].qianNode;
                    break;
                case "ZHI":
                    s = i[e].zhiNode;
                    break;
                case "WAN":
                    s = i[e].wanNode;
                    break;
                case "BUTTON":
                    break;
                default:
                    return - 1
            }
            if ( - 1 == s) return - 1;
            var o = Model.getIndexByID(s);
            if ( - 1 == o) return - 1;
            if ("TRACK" == i[o].category || "SIGNAL" == i[o].category) return s;
            if ("SWITCH" == i[o].category) return i[o].qianNode == i[e].id ? n.rp = "QIAN": i[o].zhiNode == i[e].id ? n.rp = "ZHI": i[o].wanNode == i[e].id && (n.rp = "WAN"),
                s
        }
        return s
    },
    findDeviceProperty: function(e) {
        for (var t = Model.elements,
                 n = 0; n < t.length; n++)"SWITCH" == t[n].category ? (t[n].otherSwitch = -1, t[n].otherDoubleCrossover = -1, t[n].qianNode = -1, t[n].zhiNode = -1, t[n].wanNode = -1, t[n].qinXian = "", t[n].extraButton.id = -1, t[n].extraButton.type = "") : "SIGNAL" == t[n].category ? (t[n].otherSignal = -1, t[n].qianNode = -1, t[n].houNode = -1, t[n].bingZhi = !1, t[n].chaZhi = !1, t[n].jg = -1) : (t[n].qianNode = -1, t[n].houNode = -1);
        lsb.judgeAndSetSignalAspect(),
            lsb.findDSwitch(e),
            lsb.findSignalRelation(e),
            lsb.findNetStruct(e),
            lsb.findQinXian(e),
            UI.showDebugError(lsb.lsbDataValidCheck())
    },
    findQinXian: function(e) {
        for (var t = Model.elements,
                 n = 0; n < t.length; n++) if ("QIN_XIAN" == t[n].category) {
            var i = e.getContext("2d"),
                a = t[n].component.point[0];
            i.beginPath(),
                i.rect(a.x - t[n].RADIUS, a.y - t[n].RADIUS, 2 * t[n].RADIUS, 2 * t[n].RADIUS),
                i.stroke();
            for (var o = 0; o < t.length; o++) if (n != o) if ("SWITCH" == t[o].category) i.isPointInPath(t[o].component.chaZhi[1].x, t[o].component.chaZhi[1].y) ? t[o].qinXian = "ZHI": i.isPointInPath(t[o].component.chaWan[1].x, t[o].component.chaWan[1].y) ? t[o].qinXian = "WAN": i.isPointInPath(t[o].component.chaJian[0].x, t[o].component.chaJian[0].y) && (t[o].qinXian = "JIAN");
            else if ("TRACK" == t[o].category && (i.isPointInPath(t[o].component.point[1].x, t[o].component.point[1].y) || i.isPointInPath(t[o].component.point[0].x, t[o].component.point[0].y))) for (var s = 0; s < t.length; s++) s != o && "SWITCH" == t[s].category && t[s].track == t[o].name && (Utils.inPoint(e, t[s].component.chaZhi[1], t[o].component.point[0]) ? t[s].qinXian = "ZHI": Utils.inPoint(e, t[s].component.chaWan[1], t[o].component.point[0]) ? t[s].qinXian = "WAN": Utils.inPoint(e, t[s].component.chaJian[0], t[o].component.point[0]) ? t[s].qinXian = "JIAN": Utils.inPoint(e, t[s].component.chaZhi[1], t[o].component.point[1]) ? t[s].qinXian = "ZHI": Utils.inPoint(e, t[s].component.chaWan[1], t[o].component.point[1]) ? t[s].qinXian = "WAN": Utils.inPoint(e, t[s].component.chaJian[0], t[o].component.point[1]) && (t[s].qinXian = "JIAN"))
        }
    },
    lsbDataValidCheck: function() {
        for (var e = [], t = {
                index: -1,
                tip: ""
            },
                 n = Model.elements, i = 0; i < n.length; i++) {
            if ("SWITCH" == n[i].category) {
                if ( - 1 == n[i].qianNode && -1 == n[i].zhiNode && -1 == n[i].wanNode) {
                    var a = Utils.copy(t);
                    a.index = i,
                        a.tip = n[i].name + "#道岔的岔尖、岔后和岔直节点为空，请调整道岔位置",
                        e.push(a)
                }
            } else if (("TRACK" == n[i].category || "SIGNAL" == n[i].category) && -1 == n[i].qianNode && -1 == n[i].houNode) {
                var a = Utils.copy(t);
                a.index = i,
                    a.tip = n[i].name + "的前节点、后节点为空，请调整位置,或手工输入前后节点",
                    e.push(a)
            }
            if ("" == n[i].throat && "BUTTON" != n[i].category) {
                var a = Utils.copy(t);
                a.index = i,
                    a.tip = n[i].name + "的咽喉区为空，请正确填写",
                    e.push(a)
            }
        }
        return e
    },
    setPathObjStatu: function(e, t) {
        var n = Model.elements;
        if ( - 1 != e) {
            for (var i = 0; i < lsb.routateTable.length; i++) if (lsb.routateTable[i].shapes[0].index == e) for (var a = 0; a < lsb.routateTable[i].shapes.length; a++)("SWITCH" == n[lsb.routateTable[i].shapes[a].index].category || "TRACK" == n[lsb.routateTable[i].shapes[a].index].category) && Model.setShapeStatu(lsb.routateTable[i].shapes[a], t)
        } else for (var i = 0; i < lsb.routateTable.length; i++) for (var a = 0; a < lsb.routateTable[i].shapes.length; a++) Model.setShapeStatu(lsb.routateTable[i].shapes[a], t)
    },
    setPathStatu: function(e, t) {
        var n = Model.elements;
        if ( - 1 != e) for (var a = 0; a < lsb.routateTable[e].shapes.length; a++)("SWITCH" == n[lsb.routateTable[e].shapes[a].index].category || "TRACK" == n[lsb.routateTable[e].shapes[a].index].category) && Model.setShapeStatu(lsb.routateTable[e].shapes[a], t);
        else for (var i = 0; i < lsb.routateTable.length; i++) for (var a = 0; a < lsb.routateTable[i].shapes.length; a++) Model.setShapeStatu(lsb.routateTable[i].shapes[a], t)
    },
    lsbStringData: [],
    getLsbStringData: function() {
        for (var e = lsb.routateTable,
                 t = {
                     id: -1,
                     idTong: [],
                     type: "",
                     aspect1: "",
                     aspect2: "",
                     aspect3: "",
                     number: "",
                     path: "",
                     routeType: "",
                     buttons: "",
                     keySwitch: "",
                     signalName: "",
                     signalDisplay: "",
                     signalBSQ: "",
                     switches: "",
                     conflictSignal: "",
                     tracks: "",
                     lieFC: "",
                     diaoFC: "",
                     nodes: ""
                 },
                 n = [], i = 0; i < e.length; i++) {
            var a = Utils.copy(t);
            "TONG" == e[i].type ? (a.idTong[0] = e[i].idTong[0], a.idTong[1] = e[i].idTong[1], a.id = e[i].id) : a.id = e[i].id,
                a.type = e[i].type,
                a.group = e[i].group,
                a.aspect1 = e[i].aspect[0].toString(),
                a.aspect2 = e[i].aspect[1].toString(),
                a.aspect3 = e[i].aspect[2].toString(),
                a.number = e[i].number.toString(),
                a.path = e[i].path.toString(),
                a.routeType = e[i].routeType.toString(),
                a.buttons = e[i].buttons.toString(),
                a.keySwitch = lsb.getKeySwitch(i).toString(),
                a.signalName = lsb.getStartSignalName(e[i].startSignal).toString(),
                a.signalDisplay = lsb.getStartSignalShow(e[i].startSignal).toString(),
                a.signalBSQ = lsb.getStartSignalBSQ(e[i].startSignal).toString(),
                "TONG" == a.type ? a.switches = lsb.getSwitchInLsb(i).toString() : a.switches = lsb.getSwitchInLsb(i).toString(),
                a.conflictSignal = lsb.getConflictSignalInLsb(i).toString(),
                a.tracks = lsb.getTrackInLsb(i).toString(),
                a.lieFC = e[i].faceConflictingLie.toString(),
                a.diaoFC = e[i].faceConflictingDiao.toString();
            for (var o = 0; o < e[i].shapes.length; o++) a.nodes += Model.getNameByID(e[i].shapes[o].index) + ",";
            n.push(a)
        }
        return lsb.lsbStringData = n,
            n
    },
    getLsbData: function() {
        return lsb.lsbStringData
    },
    getStartSignalName: function(e) {
        var t = Model.getNodeByID(e),
            n = Model.elements;
        return - 1 != t ? n[e].name: void 0
    },
    getStartSignalShow: function(e) {
        var t = Model.getNodeByID(e),
            n = Model.elements;
        return - 1 != t ? n[e].xianshi: void 0
    },
    getStartSignalBSQ: function(e) {
        var t = Model.getNodeByID(e),
            n = Model.elements;
        return - 1 != t ? "WUFANGXIANG" == n[e].fxbsq ? "": n[e].fxbsq: void 0
    },
    getSwitchInLsb: function(e) {
        function p(e, t) {
            for (var n = lsb.routateTable,
                     i = 0; i < n[t].shapes.length; i++) if (n[t].shapes[i].index == e) return ! 0;
            return ! 1
        }
        function c(e) {
            var t = n[e],
                i = n[Model.getIndexByID(n[e].otherSwitch)],
                a = "";
            return a = t.name < i.name ? t.name + "/" + i.name: i.name + "/" + t.name
        }
        for (var t = lsb.routateTable,
                 n = Model.elements,
                 a = [], o = 0; o < t[e].shapes.length; o++) if ("SWITCH" == t[e].shapes[o].type) {
            var s = "",
                r = Model.getIndexByID(n[t[e].shapes[o].index].otherSwitch);
            s = n[t[e].shapes[o].index].name,
            -1 != r && (s = c(t[e].shapes[o].index));
            var l = "";
            l = "FAN_WEI" == t[e].shapes[o].statu ? "(" + s + ")": s;
            for (var f = !1,
                     h = 0; h < a.length; h++) if (a[h] == l) {
                f = !0;
                break
            }
            f || a.push(l)
        }
        for (i = 0; i < t[e].fhSwitch.length; i++) {
            var s = "",
                r = Model.getIndexByID(n[t[e].fhSwitch[i].sdc.index].otherSwitch);
            s = lsb.switchName(t[e].fhSwitch[i].sdc.index, "DING_WEI"),
            -1 != r && p(r, e) && (s = lsb.switchName(t[e].fhSwitch[i].sdc.index, "DING_WEI")),
                l = "FAN_WEI" == t[e].fhSwitch[i].sdc.statu ? s: "(" + s + ")";
            for (var f = !1,
                     h = 0; h < a.length; h++) if (a[h] == l) {
                f = !0;
                break
            }
            f || a.push("[" + l + "]")
        }
        for (i = 0; i < t[e].ddSwitch.length; i++) {
            var s = "",
                r = Model.getIndexByID(n[t[e].ddSwitch[i].sdc.index].otherSwitch);
            s = n[t[e].ddSwitch[i].sdc.index].name,
            -1 != r && p(r, e) && (s = c(t[e].ddSwitch[i].sdc.index)),
                l = "FAN_WEI" == t[e].ddSwitch[i].sdc.statu ? "(" + s + ")": s;
            for (var f = !1,
                     h = 0; h < a.length; h++) if (a[h] == l) {
                f = !0;
                break
            }
            f || a.push("{" + l + "}")
        }
        return a
    },
    getConflictSignalInLsb: function(e) {
        function c(e) {
            var t = Model.getNodeByID(e.sg.index),
                n = "";
            return f = t.type,
                n = "LIE" == e.type ? "LIE" == f.match("LIE") ? t.name + "L": t.name: "LIE" == f.match("LIE") ? t.name + "D": t.name
        }
        for (var t = lsb.routateTable,
                 i = (Model.elements, []), a = 0; a < t[e].conflictingSiganl.length; a++) {
            var o = t[e].conflictingSiganl[a].sg.index;
            o = Model.getNodeByID(o);
            for (var s = "",
                     r = !1,
                     l = 0; l < t[e].conflictingSiganl.length; l++) if (a != l && t[e].conflictingSiganl[l].sg.index == t[e].conflictingSiganl[a].sg.index) {
                r = !0;
                break
            }
            s = r ? t[e].conflictingSiganl[a].sw.index == t[e].conflictingSiganl[l].sw.index ? o.name: c(t[e].conflictingSiganl[a]) : o.name;
            var f = "";
            if ( - 1 != t[e].conflictingSiganl[a].sw.index) {
                var h = t[e].conflictingSiganl[a].sw.index,
                    f = "";
                h = Model.getNodeByID(h),
                -1 != h && (f = "FAN_WEI" == t[e].conflictingSiganl[a].sw.statu ? "<(" + lsb.switchName(t[e].conflictingSiganl[a].sw.index, "DING_WEI") + ")>": "<" + lsb.switchName(t[e].conflictingSiganl[a].sw.index, "DING_WEI") + ">")
            }
            for (var r = !1,
                     p = 0; p < i.length; p++) if (i[p] == f + s) {
                r = !0;
                break
            }
            r || i.push(f + s)
        }
        return i
    },
    getTrackInLsb: function(e) {
        for (var n = lsb.routateTable,
                 a = (Model.elements, []), o = 0; o < n[e].tracks.length; o++) {
            var s = ""; - 1 != n[e].tracks[o].tw && (s = "FAN_WEI" == n[e].tracks[o].tws ? "<(" + n[e].tracks[o].tw.name + ")>": "<" + n[e].tracks[o].tw.name + ">"),
                a.push(s + n[e].tracks[o].tg)
        }
        return a
    },
    getLieFC: function(e) {
        var t = lsb.routateTable;
        return t[e].faceConflictingLie
    },
    getDiaoFC: function(e) {
        var t = lsb.routateTable;
        return t[e].faceConflictingDiao
    },
    getKeySwitch: function(e) {
        var t = lsb.routateTable,
            n = [];
        for (j = 0; j < t[e].keySwitch.length; j++) n.push(t[e].keySwitch[j].text);
        return n
    },
    getLsbSRIndex: function(e) {
        for (var t = lsb.routateTable[e].id, n = 0; n < lsb.lsbStringData.length; n++) if (lsb.lsbStringData[n].id == t) return n;
        return - 1
    },
    editBasicRouteFlag: function(e) {
        if (e = lsb.getLsbSRIndex(e), -1 != e) {
            for (var t = lsb.lsbStringData[e].group, n = lsb.lsbStringData[e].number, i = [], a = 0; a < lsb.lsbStringData.length; a++) lsb.lsbStringData[a].group == t && i.push(lsb.lsbStringData[a]);
            var o = 1;
            for (a = 0; a < i.length && "TONG" != i[a].type; a++) i[a].number == n ? i[a].routeType = 1 : (o++, i[a].routeType = o)
        }
    },
    updateTongNo: function() {
        function o(e, t) {
            for (var n = lsb.routateTable,
                     i = 0; i < n.length; i++) if (e != i && n[e].id == t) return n[e].number;
            return ""
        }
        for (var e = lsb.lsbStringData,
                 t = 0; t < e.length; t++) if ("TONG" == e[t].type) {
            var n = e[t].id[0],
                i = o(t, n),
                a = o(t, e[t].id[1]);
            e[t].number = i + "/" + a,
                lsb.lsbStringData[t].number = e[t].number.toString()
        }
    },
    updateGroupNo: function(e) {
        var t = lsb.lsbStringData[e].group,
            n = lsb.lsbStringData[e].number,
            i = [];
        if ("TONG" != lsb.lsbStringData[e].type) {
            for (var a = 0; a < lsb.lsbStringData.length; a++) lsb.lsbStringData[a].group == t && i.push(lsb.lsbStringData[a]);
            var o = lsb.lsbStringData[e].routeType;
            if (1 == o) {
                var s = 1;
                for (a = 0; a < i.length; a++) i[a].number != n && (i[a].routeType = s++)
            } else {
                var s = 2;
                for (a = 0; a < i.length; a++) 1 != i[a].routeType && (i[a].routeType = s++)
            }
        }
    }
};